import api from '../../../api/index'

const db = wx.cloud.database()
// miniprogram/pages/team/detail/detail.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    team:{
      name: 'KYC.COM',
      currNum: 8,
      needNum: 3,
      introduction:'项目已经有了一定的基础，并且参加过去年的互联网+比赛，团队氛围特别好，进来一起学习',
      contestName:'“创客杯”大学生创业大赛',
      needDatail: '需要一个比较会ps的同学，最好是相关专业的，有相关的创业竞赛的经验就最好啦，主要是不划水  ~',
      createTime: '2020-04-21',
      imgs:['/images/华农1.jpg', '/images/华农1.jpg', '/images/华农1.jpg']
    },
    user:{
      avatarUrl: '/images/华农1.jpg',
      nickName: '陈大杰',
    },
    player:{},
    show: false, // 是否显示”选择队伍”列表
    is_me:false,
    clickTrue:false, // 邀请加入 按钮是否可以被点击
  },

  /**
   * 生命周期函数--监听页面加载
   */

   
  onLoad: function (options) {
    console.log(JSON.parse(options.player))
    this.setData({
      player:JSON.parse(options.player)
    },()=>{
      var createTime = app.formatDate(this.data.team.createTime)
      this.setData({
        is_me:app.globalData.openid ==this.data.player.openid,
        ["player.createTime"] : createTime
      })
    })
  },
  cancelRece:function(){
    var contestID = this.data.player.contestID
    console.log(contestID)
    if(contestID==undefined){
      wx.showToast({
        title: '没有关联赛事',
        icon:'error'
      })
      return 0
    }
    wx.navigateTo({
      url: '../../contest/detail/detail?id='+contestID,
    })
  },
  contact: function() {
    var id1 =  this.data.player.openid
    var id2 = app.globalData.openid
    wx.navigateTo({
      url: '../../../pages/message/chartRoom/chartRoom?id1='+id1+'&id2='+id2,
    })
  },
  toLookMe: function() {
    var openid = this.data.team.openid
    console.log(openid)
    wx.navigateTo({
      url: '/pages/lookMe/lookMe?openid=' + openid,
    })
  },
  apply:function(){
    this.setData({
      show: true,
      clickTrue:true,
    })
    wx.showToast({
      title: '邀请发送成功',
    })

  },
  del:function(){
    var id = this.data.player._id
    var params = {id}
    wx.showModal({
      title: '取消发布',
      content: '确定要取消发布信息吗',
      success (res) {
        if (res.confirm) {
          console.log('用户点击确定')
          api.player.del(params).then(res=>{
            console.log(res)
            let pages = getCurrentPages();
            let prevPages = pages[pages.length - 2];
            prevPages.teamList()
            wx.navigateBack({
              delta: 1,
            })
            wx.showToast({
              title: '取消发布成功',
              icon: 'success',
              duration: 2000
            })
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
    
    
    
  },
  getTeam:function(){
    var teamID = this.data.player._id
    const that =this
    console.log(teamID)
    db.collection('team').doc(teamID).get().then(res=>{
      console.log(res)
      that.setData({
        player:res.data
      })
    })
  },
  
})